import MPRequest from '../utils/request'
import qs from 'qs'
import Security from '@/utils/security'
export const baseUrl = process.env.HOST

// 获取AccessToken的登录接口
export const authApi = async function (data) {
  console.log('authApi requesting...')
  const res = await MPRequest.post('/authorize', data)
  return res
}

// 获取首页信息接口
export const attachUpload = function (data, type) {
  return MPRequest.upload(`${baseUrl}/attachs/upload`, data, type)
}

// 获取AccessToken的登录接口
export const loginApi = async function (data) {
  console.log('loginApi requesting...')
  let paramsString = qs.stringify(data)
  let params = {
    ms: Security.encrypt(paramsString)
  }
  const res = await MPRequest.post('/passport/login/index', params)
  return res
}

// 用户注册（资料完善）
export const userAuthent = function (data) {
  console.log('userAuthent requesting...')
  let paramsString = qs.stringify(data)
  let params = {
    ms: Security.encrypt(paramsString)
  }
  return MPRequest.post('/passport/register/index', params)
}

// 发送短信验证码
export const sendcodeApi = function (data) {
  const res = MPRequest.post('/sms/code', data)
  return res
}

// 获取首页信息接口
export const homeApi = () => {
  return MPRequest.get(`${baseUrl}/home`)
}

// 获取首页信息接口
export const getIssueOptions = () => {
  return MPRequest.get(`${baseUrl}/issue`)
}

// 获取商品详情接口
export const needViewApi = function (id) {
  return MPRequest.get(`${baseUrl}/demand/default/view`, {
    id: id
  })
}

// 从购物车批量删除商品
export const publishApi = function (data) {
  return MPRequest.post(`${baseUrl}/demand/publish`, data)
}

// 从购物车批量删除商品
export const replyApi = function (data) {
  return MPRequest.post(`${baseUrl}/demand/reply`, data)
}

// 添加商品进入购物车
export const getCategoryList = function () {
  return MPRequest.get(`${baseUrl}/demand/category`)
}

// 需要结算的商品查询
export const getCategoryOptions = function () {
  return MPRequest.get(`${baseUrl}/demand/category/options`)
}

// 绑定手机号接口
export const bindMobileApi = function (data) {
  return MPRequest.post(`${baseUrl}/passport/bind-mobile`, data)
}

// 个人中心
export const getMemberInfo = function () {
  return MPRequest.get(`${baseUrl}/user/home`)
}

// 获取赛事列表
export const getNeedsList = function (params) {
  return MPRequest.get(`/demand/list/index`, params)
}

// 检索列表
export const getSearchList = function (params) {
  return MPRequest.get(`/search`, params)
}
